#
# Copyright 2024 Kumo.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
# below are examples, after initialization, modify it to your own.
###########################################################################
###kmcmake_example

#[[
file(GLOB_RECURSE UTILITY_SRC "utility/*.cc")
kmcmake_cc_library(
        NAMESPACE ${PROJECT_NAME}
        NAME utility
        SOURCES
        ${UTILITY_SRC}
        ${CONFIG_SRC}
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        PLINKS
        ${KMCMAKE_DEPS_LINK}
)
]]
set(TARGET_SRCS)

set(PUBLIC_ASSETS
        index.html
        completion.js
        loading.html
        deps_daisyui.min.css
        deps_markdown-it.js
        deps_tailwindcss.js
        deps_vue.esm-browser.js
        favicon.png
        kumo_logo.svg
        )

foreach(asset ${PUBLIC_ASSETS})
    set(input "${CMAKE_CURRENT_SOURCE_DIR}/public/${asset}")
    set(output "${CMAKE_CURRENT_SOURCE_DIR}/public/${asset}.h")
    list(APPEND TARGET_SRCS ${output})
    add_custom_command(
            DEPENDS "${input}"
            OUTPUT "${output}"
            COMMAND "${CMAKE_COMMAND}" "-DINPUT=${input}" "-DOUTPUT=${output}" -P "${PROJECT_SOURCE_DIR}/cmake/xxd.cmake"
    )
endforeach()

file(GLOB_RECURSE UTILITY_SRC "utility/*.cc")
file(GLOB_RECURSE CORE_SRC "core/*.cc")
file(GLOB_RECURSE OPAI_SRC "openai/*.cc")
file(GLOB_RECURSE KAI_SRC "kai/*.cc")
file(GLOB_RECURSE CONFIG_SRC "config/*.cc")
kmcmake_cc_library(
        NAMESPACE ${PROJECT_NAME}
        NAME core
        SOURCES
        ${COMMON_SRC}
        ${UTILITY_SRC}
        ${CORE_SRC}
        ${OPAI_SRC}
        ${KAI_SRC}
        ${TARGET_SRCS}
        ${CONFIG_SRC}
        OBJECTS
        proto_obj
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        PLINKS
        ${KMCMAKE_DEPS_LINK}
)

file(GLOB_RECURSE SERVICE_SRC "tools/*.cc")

kmcmake_cc_binary(
        NAMESPACE ${PROJECT_NAME}
        NAME kllm
        SOURCES
        ${SERVICE_SRC}
        ${TARGET_SRCS}
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        LINKS
        ${PROJECT_NAME}::core_static
        ${KMCMAKE_DEPS_LINK}
        PUBLIC
)

#[[
file(GLOB TOOLS_SRC "tools/*.cc")
kmcmake_cc_binary(
        NAMESPACE ${PROJECT_NAME}
        NAME kllm
        SOURCES
        ${TOOLS_SRC}
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        LINKS
        ${PROJECT_NAME}::utility_static
        ${KMCMAKE_DEPS_LINK}
        PUBLIC
)
]]
###kmcmake_example